package com.itpeng.service.Impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.itpeng.Utils.DateUtils;
import com.itpeng.dao.MemberDao;
import com.itpeng.dao.OrderDao;
import com.itpeng.pojo.Order;
import com.itpeng.service.MemberService;
import com.itpeng.service.ReportService;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Aythor:彭彦钦
 * @Data: 2020/9/29  22:08
 */
@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;


    /**
     * 运营数据统计
     * @return
     */
    @Override
    public Map<String, Object> getBusinessReportData() {
        /*
            reportDate:null,
            todayNewMember :0,
            totalMember :0,
            thisWeekNewMember :0,
            thisMonthNewMember :0,

            todayOrderNumber :0,
            todayVisitsNumber :0,
            thisWeekOrderNumber :0,
            thisWeekVisitsNumber :0,
            thisMonthOrderNumber :0,
            thisMonthVisitsNumber :0,

            hotSetmeal :[
                {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222,remark:'垃圾'},
                {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
            ]
         */
        Map<String,Object> dataMap = new HashMap<String, Object>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //今日日期
        String toDay = sdf.format(new Date());
        //本周周一的日期
        String thisWeekMonday = sdf.format(DateUtils.getThisWeekMonday());
        //本周周天日期
        String sundayOfThisWeek = sdf.format(DateUtils.getSundayOfThisWeek());
        //本月月初日期
        String firstDayOfThisMonth = sdf.format(DateUtils.getFirstDayOfThisMonth());
        //本月月末日期
        String lastDayOfThisMonth = sdf.format(DateUtils.getLastDayOfThisMonth());
        //存入日期
        dataMap.put("reportDate", toDay);


        //============== 会员数据统计 ================
        //今日新增会员数
        int todayNewMember = memberDao.findMemberCountByDate(toDay);
        dataMap.put("todayNewMember",todayNewMember);
        //总会员数
        int totalMember = memberDao.findMemberTotalCount();
        dataMap.put("totalMember",totalMember);
        //本周新增会员数
        int thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        dataMap.put("thisWeekNewMember",thisWeekNewMember);
        //本月新增会员数
        int thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDayOfThisMonth);
        dataMap.put("thisMonthNewMember",thisMonthNewMember);

        //============== 预约到诊数据统计 ================
        //今日预约数
        int todayOrderNumber = orderDao.findOrderCountByDate(toDay);
        dataMap.put("todayOrderNumber",todayOrderNumber);
        //今日到诊数
        int todayVisitsNumber = orderDao.findVisitsCountByDate(toDay);
        dataMap.put("todayVisitsNumber",todayVisitsNumber);
        //本周预约数
        int thisWeekOrderNumber = orderDao.findOrderCountBetweenDate(thisWeekMonday,sundayOfThisWeek);
        dataMap.put("thisWeekOrderNumber",thisWeekOrderNumber);
        //本周到诊数
        int thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekMonday,sundayOfThisWeek);
        dataMap.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        //本月预约数
        int thisMonthOrderNumber = orderDao.findOrderCountBetweenDate(firstDayOfThisMonth,lastDayOfThisMonth);
        dataMap.put("thisMonthOrderNumber",thisMonthOrderNumber);
        //本月到诊数
        int thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDayOfThisMonth,lastDayOfThisMonth);
        dataMap.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        //============== 热门套餐统计 ================
        List<Map<String,Object>> hotSetmeal = orderDao.findHotSetmeal();
        dataMap.put("hotSetmeal", hotSetmeal);
        return dataMap;
    }
}
